//
//  FLLSetPasswordViewController.m
//  FLLGodOfCookery
//
//  Created by LL.F on 16/8/29.
//  Copyright © 2016年 LL.F. All rights reserved.
//

#import "FLLSetPasswordViewController.h"
#import "FLLMacro.h"
#import "FLLLoginAndRegisterTextField.h"
#import "MBProgressHUD.h"
#import "FLLMineViewController.h"
#import "LoginData.h"
#import "NSString+FLL_MD5.h"
@interface FLLSetPasswordViewController ()
@property (weak, nonatomic) IBOutlet FLLLoginAndRegisterTextField *passwordField;
@property (weak, nonatomic) IBOutlet FLLLoginAndRegisterTextField *repeatPassword;
@property (weak, nonatomic) IBOutlet FLLLoginAndRegisterTextField *nickField;

@end

@implementation FLLSetPasswordViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    
}
// 隐藏顶部 navigationBar
// 隐藏顶部 navigationBar后就不会有左滑返回的效果了
- (void)viewWillAppear:(BOOL)animated
{
    
    self.navigationController.navigationBarHidden = YES;
    // 实现隐藏顶部navigationBar也有左滑返回的效果<3>
    [self.navigationController.view sendSubviewToBack:self.navigationController.navigationBar];
    self.tabBarController.tabBar.hidden = YES;
    
    
}
- (void)viewWillDisappear:(BOOL)animated
{
    
    self.navigationController.navigationBarHidden = NO;
    // 实现隐藏顶部navigationBar也有左滑返回的效果<4>
    [self.navigationController.view bringSubviewToFront:self.navigationController.navigationBar];
    self.tabBarController.tabBar.hidden = NO;
    
}

- (IBAction)didClickedBackToRegisterButton:(id)sender
{
    [self.navigationController popViewControllerAnimated:YES];
}
// 点击注册按钮完成注册
- (IBAction)didClickedRegisterButton:(id)sender
{
    NSString *user_id = [NSString stringWithFormat:@"%zd", self.loginData.data.user_id];
    NSString *nickname = self.loginData.data.nickname;
    NSString *token = self.loginData.data.token;
    NSString *password = [self.passwordField.text stringWith32BitMD5Lower];
    NSLog(@"%@", user_id);
    NSString *bodyString = [NSString stringWithFormat:@"user_id=%@&nickname=%@&password=%@&token=%@&methodName=UserPwd&version=4.40&", user_id, nickname, password, token];
    [ZWYNetTool POST:@"http://api.izhangchu.com/" andBody:bodyString andBodyStyle: ZWYBodyString andHeader:@{@"Content-Type":@"application/x-www-form-urlencoded"} andResponse:ZWYJSON andSuccessBlock:^(id result) {
        
        NSLog(@"完成注册");
        NSLog(@"%@", result);
        FLLMineViewController *mineVC = [[FLLMineViewController alloc] init];
        mineVC.loginModel = self.loginData;
        [self.navigationController popToRootViewControllerAnimated:YES];
        
    } andFailureBlock:^(NSError *error) {
        
    
    }];

}
//// 隐藏底部 tabBar
//- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
//{
//    
//    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
//    if (self) {
//        self.hidesBottomBarWhenPushed = YES;
//    }
//    return self;
//}
- (void)setLoginData:(FLLLoginModel *)loginData
{

    _loginData = loginData;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
